-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add logout logic #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds client-side logout support by introducing a logout API call plus React Query mutation/hook wrappers, integrating session cleanup and navigation on logout.
Changes:
- Added
logoutApi()to call the server logout endpoint. - Added
useLogoutMutation()to perform logout and clear client auth/query state. - Added a
useLogout()hook wrapper to exposelogout,isPending, anderror.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
client/src/hooks/useLogout.ts |
Provides a small hook wrapper around the logout mutation for component use. |
client/src/features/auth/mutations/useLogoutMutation.ts |
Implements the logout mutation and client-side cleanup (session/cache/nav). |
client/src/api/auth/auth.api.ts |
Adds the /api/auth/logout API call used by the mutation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| onSuccess: async () => { | ||
| clearSession(); | ||
| localStorage.removeItem("hadSession"); | ||
| qc.clear(); | ||
| navigate("/", { replace: true }); | ||
| }, | ||
| onError: (error) => { | ||
| console.error("Logout failed:", error); | ||
| clearSession(); | ||
| localStorage.removeItem("hadSession"); | ||
| qc.clear(); | ||
| navigate("/", { replace: true }); | ||
| }, |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onSuccess and onError contain the same logout cleanup logic (clear session, remove localStorage flag, clear query cache, navigate). This duplication increases the risk of future drift; consider extracting a shared helper or using onSettled to run the common cleanup once, while keeping error logging separate if needed.
| clearSession(); | ||
| localStorage.removeItem("hadSession"); | ||
| qc.clear(); | ||
| navigate("/", { replace: true }); | ||
| }, | ||
| onError: (error) => { | ||
| console.error("Logout failed:", error); | ||
| clearSession(); | ||
| localStorage.removeItem("hadSession"); | ||
| qc.clear(); | ||
| navigate("/", { replace: true }); |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The app already has a centralized “hard logout” flow via triggerLogout/AuthBootstrap (used by the Axios interceptors). Implementing separate cleanup/navigation logic here can lead to inconsistent behavior across logout paths. Consider reusing the centralized handler (and ensuring it also removes hadSession) so all logout entrypoints share one implementation.
client/src/api/auth/auth.api.ts
Outdated
| export async function logoutApi() { | ||
| const res = await apiProtected.post("/api/auth/logout"); | ||
| return res.data; | ||
| } |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logoutApi returns res.data with an implicit any type, but callers don’t use the return value. To keep API helpers consistent with register*Api (which just awaits the request) and improve typing, consider returning Promise<void> (or a specific response type if it’s meaningful) and avoid returning untyped data.
| export async function logoutApi() { | |
| const res = await apiProtected.post("/api/auth/logout"); | |
| return res.data; | |
| } | |
| export async function logoutApi(): Promise<void> { | |
| await apiProtected.post("/api/auth/logout"); | |
| } |
Dmytro-Doronin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change everything that Copilot suggests you and call logOut api inside log out modal
client/src/hooks/useLogout.ts
Outdated
| @@ -0,0 +1,14 @@ | |||
| import { useLogoutMutation } from "../features/auth/mutations/useLogoutMutation"; | |||
|
|
|||
| export const useLogout = () => { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need this hook, you can use useLogoutMutation directly in header component
No description provided.